$(document).ready(function() {
	$("#loading").ajaxStart(function(){
	   $(this).show();
	 });
	
	$("#loading").ajaxStop(function(){
	   $(this).slideUp('slow');
	 });
	
	$('.hlist li a').css('cursor','pointer');
	$('#control .hlist li').first().css('border-left','none');
	$('#menu-bar .hlist li').first().css('border-left','none');
	
	$('a[name|="delete"]').click(function(event){
		event.preventDefault();
		var fldName = event.target.name;
		var id = fldName.substring(fldName.indexOf('-')+1);
		$.post('photo-delete', 
			{ids: id},
			function(data) {
				$('#'+id).slideUp();
		});
	});
	
	$('a[name|="caption"]').click(function(event){
		event.preventDefault();
		var fldName = event.target.name;
		var id = fldName.substring(fldName.indexOf('-')+1);
		var caption = $('#'+id+' textarea').attr('value');
		
		$.post('photo-save', 
			{ids: id, captions: caption},
			function(data) {
				$('#notification').html(data).slideDown().delay(5000).fadeOut('slow');
		});
		
	});
	
	$('a[name|="default"]').click(function(event){
		event.preventDefault();
		var fldName = event.target.name;
		var id = fldName.substring(fldName.indexOf('-')+1);
		$('.selected').removeClass('selected');
		$('#'+id).addClass('selected');
		$.post('photo-default', 
			{ids: id},
			function(data) {
				$('#notification').html(data).slideDown().delay(5000).fadeOut('slow');
		});
	});
	
	$('.image-tool :input').click(function(event){
		var msgNew = event.target.value;
		var msgDefault = $(':hidden[name="defaultMsg"]').attr('value');
		if(msgNew.trim() == msgDefault.trim()) {
			event.target.value = '';
		}
	});
	
	$('.image-tool :input').blur(function(event){
		var msgNew = event.target.value;
		if(msgNew == '') {
			event.target.value = $(':hidden[name="defaultMsg"]').attr('value');
		}
	});
	
	$('.notify').click(function(event){
		event.preventDefault();
		$('#notification').toggle();
	});
});